package com.huawei.appmarket.service.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appmarket.framework.app.StoreApplication;
import com.huawei.appmarket.support.storage.referrer.AppReferrerRecord;
import java.util.List;
import o.diu;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.dpl;
import o.dss;
import o.dsu;
import o.dyo;
import o.eop;
import o.eqp;
import o.eua;
import o.eue;
import o.eug;
import o.eun;

public class CommonDataProvider extends ContentProvider {
    private static final String ˋ = (StoreApplication.getInstance().getPackageName() + ".commondata");
    private static final UriMatcher ˏ = new UriMatcher(-1);

    static {
        ˏ.addURI(ˋ, "item/1", 1);
        ˏ.addURI(ˋ, "item/2", 2);
        ˏ.addURI(ˋ, "item/3", 3);
        ˏ.addURI(ˋ, "item/4", 4);
        ˏ.addURI(ˋ, "item/5", 5);
        ˏ.addURI(ˋ, "item/6", 6);
    }

    public boolean onCreate() {
        eop.ˏ();
        return true;
    }

    @Nullable
    public Cursor query(@NonNull Uri uri, @Nullable String[] strArr, @Nullable String str, @Nullable String[] strArr2, @Nullable String str2) {
        dpl.ˋ(ContentManager.getInstant().getContext(), 15);
        switch (ˏ.match(uri)) {
            case 1:
                return ˎ();
            case 2:
                return ˋ();
            case 3:
                return ॱ(str);
            case 4:
                return ˏ();
            case 5:
                return ˏ(strArr2[0]);
            case 6:
                return ˎ(str);
            default:
                return null;
        }
    }

    private MatrixCursor ˎ() {
        if (diu.ˊ().ˎ()) {
            MatrixCursor matrixCursor = new MatrixCursor(new String[]{"homecountry"}, 1);
            matrixCursor.addRow(new Object[]{eqp.ॱ()});
            Logger.ˎ("CommonDataProvider", "provider getHomeCountry:" + r1);
            return matrixCursor;
        }
        Logger.ˎ("CommonDataProvider", "not agree protocol,could not query accountzone!");
        return null;
    }

    private MatrixCursor ˋ() {
        if (diu.ˊ().ˎ()) {
            String callingPackage = getCallingPackage();
            Logger.ˏ("CommonDataProvider", "calling packageName = " + callingPackage);
            if (TextUtils.isEmpty(callingPackage)) {
                Logger.ˋ("CommonDataProvider", "access failure, packageName is null");
                return null;
            }
            String[] ˏ = eue.ˎ().ˏ(callingPackage);
            if (ˏ == null) {
                return null;
            }
            Object obj = ˏ[0];
            String str = ˏ[1];
            if (!TextUtils.isEmpty(obj)) {
                dyo.ˏ(obj);
            }
            MatrixCursor matrixCursor = new MatrixCursor(new String[]{"initParam"}, 1);
            matrixCursor.addRow(new Object[]{str});
            Logger.ˎ("CommonDataProvider", "provider getInitParam:" + str);
            eue.ˎ().ˋ(callingPackage);
            return matrixCursor;
        }
        Logger.ˎ("CommonDataProvider", "not agree protocol,could not getInitParams!");
        return null;
    }

    private MatrixCursor ˎ(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("CommonDataProvider", "access failure, packageName is null");
            return null;
        }
        Logger.ˎ("CommonDataProvider", "package name = " + str);
        if (diu.ˊ().ˎ()) {
            Object string;
            MatrixCursor matrixCursor;
            CharSequence ˊ = eug.ˏ().ˊ(str);
            if (TextUtils.isEmpty(ˊ)) {
                Cursor query = ContentManager.getInstant().getContext().getContentResolver().query(Uri.parse("content://com.huawei.gamebox.commondata/item/6"), null, str, null, null);
                if (query != null && query.moveToFirst()) {
                    string = query.getString(0);
                    query.close();
                    if (!TextUtils.isEmpty(string)) {
                        return null;
                    }
                    matrixCursor = new MatrixCursor(new String[]{str}, 1);
                    matrixCursor.addRow(new Object[]{string});
                    Logger.ˎ("CommonDataProvider", "provider getDetailId:" + string);
                    return matrixCursor;
                }
            }
            CharSequence charSequence = ˊ;
            if (!TextUtils.isEmpty(string)) {
                return null;
            }
            matrixCursor = new MatrixCursor(new String[]{str}, 1);
            matrixCursor.addRow(new Object[]{string});
            Logger.ˎ("CommonDataProvider", "provider getDetailId:" + string);
            return matrixCursor;
        }
        Logger.e("CommonDataProvider", "not agree protocol,could not query account zone!");
        return null;
    }

    private MatrixCursor ॱ(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("CommonDataProvider", "access failure, packageName is null");
            return null;
        }
        Logger.ˎ("CommonDataProvider", "package name = " + str);
        if (diu.ˊ().ˎ()) {
            List ˊ;
            MatrixCursor matrixCursor;
            String callingPackage = getCallingPackage();
            if (callingPackage.equals(str)) {
                ˊ = eun.ˏ().ˊ(str, null);
            } else {
                Logger.ˎ("CommonDataProvider", "calling package name = " + callingPackage);
                ˊ = eun.ˏ().ˊ(str, callingPackage);
            }
            if (ˊ.size() != 0) {
                MatrixCursor matrixCursor2 = new MatrixCursor(new String[]{"trackId"}, 1);
                for (int i = 0; i < ˊ.size(); i++) {
                    matrixCursor2.addRow(new Object[]{((AppReferrerRecord) ˊ.get(i)).ˎ()});
                    Logger.ˎ("CommonDataProvider", "provider getTrackId:" + callingPackage);
                }
                matrixCursor = matrixCursor2;
            } else {
                matrixCursor = null;
            }
            return matrixCursor;
        }
        Logger.e("CommonDataProvider", "not agree protocol,could not query account zone!");
        return null;
    }

    private MatrixCursor ˏ(String str) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("CommonDataProvider", "access failure, packageName is null");
            return null;
        }
        Logger.ˎ("CommonDataProvider", "package name = " + str);
        if (diu.ˊ().ˎ()) {
            List ˊ;
            MatrixCursor matrixCursor;
            String callingPackage = getCallingPackage();
            if (str.equals(callingPackage)) {
                ˊ = eun.ˏ().ˊ(str, null);
            } else {
                Logger.ˎ("CommonDataProvider", "calling package name = " + callingPackage);
                ˊ = eun.ˏ().ˊ(str, callingPackage);
            }
            if (ˊ.size() != 0) {
                MatrixCursor matrixCursor2 = new MatrixCursor(new String[]{"referrer", "clickTime", "installTime"});
                for (int i = 0; i < ˊ.size(); i++) {
                    matrixCursor2.addRow(new Object[]{dof.ˊ(r0.ˎ()), Long.valueOf(r0.ˋ()), Long.valueOf(((AppReferrerRecord) ˊ.get(i)).ॱ())});
                    Logger.ˎ("CommonDataProvider", "provider getReferrer:" + r0.ˎ());
                }
                matrixCursor = matrixCursor2;
            } else {
                matrixCursor = null;
            }
            return matrixCursor;
        }
        Logger.e("CommonDataProvider", "not agree protocol,could not query account zone!");
        return null;
    }

    private MatrixCursor ˏ() {
        boolean ˎ = diu.ˊ().ˎ();
        MatrixCursor matrixCursor = new MatrixCursor(new String[]{"isAgree", "isOpenAutoUpdate", "isNeverReminder"}, 1);
        if (!ˎ) {
            Logger.ˎ("CommonDataProvider", "not agree protocl");
            matrixCursor.addRow(new Object[]{Boolean.valueOf(ˎ), Boolean.valueOf(false), Boolean.valueOf(true)});
        } else if (new dsu().ॱ(ContentManager.getInstant().getContext())) {
            boolean ˎ2 = dss.ॱ().ˎ();
            Logger.ˎ("CommonDataProvider", "provider getAutoUpdateInfo,isAgree=" + ˎ + ",isOpenAutoUpdate=" + ˎ2 + ",isNeverReminder=" + eua.ˏ().ˏ("never_reminder_auto_update", false));
            matrixCursor.addRow(new Object[]{Boolean.valueOf(ˎ), Boolean.valueOf(ˎ2), Boolean.valueOf(r3)});
        } else {
            matrixCursor.addRow(new Object[]{Boolean.valueOf(ˎ), Boolean.valueOf(false), Boolean.valueOf(true)});
        }
        return matrixCursor;
    }

    @Nullable
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
        return null;
    }

    public int delete(@NonNull Uri uri, @Nullable String str, @Nullable String[] strArr) {
        return 0;
    }

    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String str, @Nullable String[] strArr) {
        return 0;
    }
}
